package org.seven.jrdp.web.t.plugins;

import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;

public class ExcelPlugin {
	public CellStyle FONT10;
	public CellStyle STYLE_FONT10;
	public CellStyle STYLE_FONT10_BOLD;
	public CellStyle STYLE_FONT10_RED;
	public CellStyle STYLE_FONT8;

	public ExcelPlugin(Workbook workbook) {
		{
			Font font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 10);
			FONT10 = workbook.createCellStyle();
			FONT10.setFont(font);
			FONT10.setWrapText(true);
			FONT10.setAlignment(CellStyle.ALIGN_CENTER);
			FONT10.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		}
		{
			Font font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 10);
			STYLE_FONT10 = workbook.createCellStyle();
			STYLE_FONT10.setFont(font);
			STYLE_FONT10.setWrapText(true);
			STYLE_FONT10.setAlignment(CellStyle.ALIGN_CENTER);
			STYLE_FONT10.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
			STYLE_FONT10.setBorderTop(CellStyle.BORDER_THIN);
			STYLE_FONT10.setBorderBottom(CellStyle.BORDER_THIN);
			STYLE_FONT10.setBorderLeft(CellStyle.BORDER_THIN);
			STYLE_FONT10.setBorderRight(CellStyle.BORDER_THIN);
		}
		{
			Font font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 10);
			font.setBold(true);
			STYLE_FONT10_BOLD = workbook.createCellStyle();
			STYLE_FONT10_BOLD.setFont(font);
			STYLE_FONT10_BOLD.setWrapText(true);
			STYLE_FONT10_BOLD.setAlignment(CellStyle.ALIGN_CENTER);
			STYLE_FONT10_BOLD.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
			STYLE_FONT10_BOLD.setBorderTop(CellStyle.BORDER_THIN);
			STYLE_FONT10_BOLD.setBorderBottom(CellStyle.BORDER_THIN);
			STYLE_FONT10_BOLD.setBorderLeft(CellStyle.BORDER_THIN);
			STYLE_FONT10_BOLD.setBorderRight(CellStyle.BORDER_THIN);
		}
		{
			Font font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 10);
			font.setColor(Font.COLOR_RED);
			font.setBold(true);
			STYLE_FONT10_RED = workbook.createCellStyle();
			STYLE_FONT10_RED.setFont(font);
			STYLE_FONT10_RED.setWrapText(true);
			STYLE_FONT10_RED.setAlignment(CellStyle.ALIGN_CENTER);
			STYLE_FONT10_RED.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
			STYLE_FONT10_RED.setBorderTop(CellStyle.BORDER_THIN);
			STYLE_FONT10_RED.setBorderBottom(CellStyle.BORDER_THIN);
			STYLE_FONT10_RED.setBorderLeft(CellStyle.BORDER_THIN);
			STYLE_FONT10_RED.setBorderRight(CellStyle.BORDER_THIN);
		}
		{
			Font font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 8);
			STYLE_FONT8 = workbook.createCellStyle();
			STYLE_FONT8.setFont(font);
			STYLE_FONT8.setAlignment(CellStyle.ALIGN_CENTER);
			STYLE_FONT8.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
			STYLE_FONT8.setBorderTop(CellStyle.BORDER_THIN);
			STYLE_FONT8.setBorderBottom(CellStyle.BORDER_DOUBLE);
			STYLE_FONT8.setBorderLeft(CellStyle.BORDER_THIN);
			STYLE_FONT8.setBorderRight(CellStyle.BORDER_THIN);
		}
	}

	public String getColumn(int i) {
		String strResult = "";
		int intRound = i / 26;
		int intMod = i % 26;
		if (intRound != 0) {
			strResult = String.valueOf(((char) (intRound + 64)));
		}
		strResult += String.valueOf(((char) (intMod + 64)));
		return strResult;
	}

	public int getColumn(String name) {
		int column = -1;
		for (int i = 0; i < name.length(); ++i) {
			int c = name.charAt(i);
			column = (column + 1) * 26 + c - 'A';
		}
		return column;
	}
}